import json


# 定义统一格式的响应体


class JsonResponse:
    Code = 0  # 状态码   int
    Flag = None  # 标志   bool
    Data = object  # 数据   list,dict,元组,自定义的实体类
    Message = ""  # 提示信息   string

    def __init__(self, code, flag, data, message):
        self.Code = code
        self.Flag = flag
        self.Data = data
        self.Message = message

    @classmethod
    def JsonResp(cls, code, flag, data, message):
        jsonResponse = JsonResponse(code, flag, data, message)
        # 将对象字典化后json序列化
        return json.dumps(jsonResponse.__dict__, ensure_ascii=False)  # 防止中文乱码ensure_ascii=False
